package com.qf.controller;

import com.qf.Resp.BaseResp;
import com.qf.loanapplication.Loanapplication;
import com.qf.operators.Operators;
import com.qf.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class BorrowController {

    @Autowired
    BorrowService borrowService;

    /*（单表）对申请人的申请表进行id进行查看*/
    @RequestMapping("/selectOneById")
    public BaseResp selectOneById(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");
        Loanapplication loanapplication = borrowService.selectOneById(id);
        BaseResp baseResp = new BaseResp();
        baseResp.setMessage(loanapplication);
        baseResp.setCode(10004l);
        System.out.println("baseResp = " + baseResp);
        return baseResp;
    }

    /*对单表进行增加*/
    @RequestMapping("/insertOneProposer")
    public BaseResp insertOneProposer(@RequestBody Loanapplication loanapplication){
        BaseResp baseResp = new BaseResp();
        int i = borrowService.insertOneProposer(loanapplication);
        if(i==1){
            baseResp.setCode(2320l);
            baseResp.setMessage("增加成功");
            return baseResp;
        }else{
            baseResp.setCode(2322l);
            baseResp.setMessage("增加失败");
            return baseResp;
        }
    }
    /*对申请人的申请表进行id进行修改*/
    @RequestMapping("/updateOneProposerById")
    public BaseResp updateOneProposerById(@RequestBody Loanapplication loanapplication){
        BaseResp baseResp = new BaseResp();
        int i = borrowService.updateOneProposerById(loanapplication);
        //System.out.println("i = " + i);
        if(i==1){
            baseResp.setCode(2300l);
            baseResp.setMessage("修改成功");
            return baseResp;
        }else{
            baseResp.setCode(2301l);
            baseResp.setMessage("修改失败");
            return baseResp;
        }
    }

    /*对申请人的申请表进行id删除*/
    @RequestMapping("/deleteOneProposerById")
    public BaseResp deleteOneProposerById(@RequestBody Map map){
        Integer id=(Integer)map.get("id");
        int i = borrowService.deleteOneProposerById(id);
        BaseResp baseResp=new BaseResp();
        if(i==1){
            baseResp.setCode(2010l);
            baseResp.setMessage("删除成功");
            return baseResp;
        }else{
            baseResp.setCode(2011l);
            baseResp.setMessage("删除失败");
            return baseResp;
        }
    }

}
